package com.trussspan.main;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.border.BevelBorder;
import javax.swing.table.DefaultTableModel;

public class MainFrame extends JFrame {

    private Container container;
    private JPanel questionPanel;
    private JPanel buttonPanel;
    private JPanel outputPanel;
    private JLabel trussTypeLabel;
    private JTextField trussSpanField;
    private JComboBox trussTypeCombo;
    private JLabel trussSpanLabel;
    private JLabel pitchLabel;
    private JTextField pitchField;
    private JLabel spacingsLabel;
    private JTextField spacingsField;
    private JLabel topSpacingsLabel;
    private JTextField topSpacingsField;
    private JLabel reactionLabel;
    private JTextField reactionField;
    private JButton calculateButton;
    String trussType;
    String trussSpan;
    double pitch;
    int spacings;
    double reaction;
    private JTable pitchDisplayTable;
    private DefaultTableModel pitchModel = new DefaultTableModel();
    private JTable wDisplayTable;
    private DefaultTableModel wModel = new DefaultTableModel();
    JTextField wFields[];
    JTextField aFields[];
    JTextField fFields[];
    JButton addWidthsButton;
    JButton addAsButton;
    JButton addForcesButton;
    JPanel widthsPanel;
    double widths[];
    double forces[];
    int topSpacings;
    double as[];

    public MainFrame() {
        super("Welcome to Truss Span");
        container = this.getContentPane();
        container.setLayout(new BorderLayout());
        questionPanel = new JPanel();
        questionPanel.setBorder(new BevelBorder(BevelBorder.RAISED));

        trussTypeLabel = new JLabel("What is the truss type?");
        String trussTypes[] = {"Howe", "Fink"};
        trussTypeCombo = new JComboBox(trussTypes);
        container.add(questionPanel, BorderLayout.CENTER);

        DropdownActionListener dropdownListener = new DropdownActionListener();
        trussTypeCombo.addActionListener(dropdownListener);

        questionPanel.setLayout(new GridLayout(7, 2));
        questionPanel.add(trussTypeLabel);
        questionPanel.add(trussTypeCombo);

        trussSpanField = new JTextField();
        trussSpanLabel = new JLabel("What is the truss span?");
        questionPanel.add(trussSpanLabel);
        questionPanel.add(trussSpanField);

        pitchField = new JTextField();
        pitchLabel = new JLabel("What is the pitch (in degrees)?");
        questionPanel.add(pitchLabel);
        questionPanel.add(pitchField);


        spacingsField = new JTextField();
        spacingsLabel = new JLabel("How many spacings are there?");
        questionPanel.add(spacingsLabel);
        questionPanel.add(spacingsField);



        reactionField = new JTextField();
        reactionLabel = new JLabel("Reaction?");
        questionPanel.add(reactionLabel);
        questionPanel.add(reactionField);

        //addding button panel
        buttonPanel = new JPanel();
        container.add(buttonPanel, BorderLayout.NORTH);

        //addding calculate button.
        calculateButton = new JButton("Calculate");
        buttonPanel.add(calculateButton);


        outputPanel = new JPanel();

        container.add(outputPanel, BorderLayout.SOUTH);
        ButtonListener listen = new ButtonListener();
        calculateButton.addActionListener(listen);
        setBounds(0, 0, getPreferredSize().width + 20, getPreferredSize().height + 20);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        pitchModel = new DefaultTableModel();
        pitchDisplayTable = new JTable(pitchModel);
        pitchDisplayTable.setPreferredScrollableViewportSize(new Dimension(400, 400));
        pitchDisplayTable.setFillsViewportHeight(true);
        pitchModel.addColumn("Field");
        pitchModel.addColumn("Value");

        JScrollPane tablePane = new JScrollPane(pitchDisplayTable);
        outputPanel.add(tablePane);



        ///
        wModel = new DefaultTableModel();
        wDisplayTable = new JTable(wModel);
        wDisplayTable.setPreferredScrollableViewportSize(new Dimension(400, 400));
        wDisplayTable.setFillsViewportHeight(true);
        wModel.addColumn("Field");
        wModel.addColumn("Value");
        JScrollPane wTablePane = new JScrollPane(wDisplayTable);
        outputPanel.add(wTablePane);

        widthsPanel = new JPanel();
        container.add(widthsPanel, BorderLayout.EAST);

        setResizable(false);
        String lookAndFeel = null;
        lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();
        try {
            UIManager.setLookAndFeel(lookAndFeel);
        } catch (Exception e) {
            e.printStackTrace(System.out);
        }

    }

    class ButtonListener implements ActionListener {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (e.getSource() == calculateButton) {
                boolean valid = true;
                while (pitchModel.getRowCount() > 0) {
                    pitchModel.removeRow((pitchModel.getRowCount() - 1));
                }
                trussType = trussTypeCombo.getSelectedItem().toString();
                trussSpan = trussSpanField.getText();

                pitchModel.addRow(new Object[]{"Truss Type", trussType});
                pitchModel.addRow(new Object[]{"Truss Span", trussSpan});

                try {
                    spacings = Integer.parseInt(spacingsField.getText());
                    if (trussType.equals("Fink")) {
                        spacingsLabel.setText("How many bottom spacings are there?");
                    } else {
                        spacingsLabel.setText("How many spacings are there?");
                    }
                    if (spacings <= 0) {
                        if (trussType.equals("Fink")) {
                            spacingsLabel.setText("How many bottom spacings are there?(Bottom Spacings must be greater 0)");
                        } else {
                            spacingsLabel.setText("How many spacings are there?(Spacings must be greater 0)");
                        }
                    }
                } catch (NumberFormatException nfe) {
                    if (trussType.equals("Fink")) {
                        spacingsLabel.setText("How many spacings are there?(Spacings must be in figures)");
                    } else {
                        spacingsLabel.setText("How many bottom spacings are there?(bottom Spacings must be in figures)");
                    }
                    valid = false;
                }
                spacingsLabel.updateUI();
                try {
                    pitch = Double.parseDouble(pitchField.getText());
                    pitchLabel.setText("What is the pitch (in degrees)?");

                } catch (NumberFormatException nfe) {
                    pitchLabel.setText("What is the pitch(in degrees)?(Pitch must be in figures)");
                    valid = false;
                }
                pitchLabel.updateUI();
                try {
                    reaction = Double.parseDouble(reactionField.getText());
                    reactionLabel.setText("Reaction");
                    pitchModel.addRow(new Object[]{"Reaction", reaction});
                } catch (NumberFormatException nfe) {
                    reactionLabel.setText("Reaction(Reaction must be in figures)");
                    valid = false;
                }
                reactionLabel.updateUI();
                if (trussType.equals("Fink")) {
                    try {
                        topSpacings = Integer.parseInt(topSpacingsField.getText());
                        topSpacingsLabel.setText("How many top spacings are there?");
                        pitchModel.addRow(new Object[]{"Top Spacings", topSpacings});
                    } catch (NumberFormatException nfe) {
                        topSpacingsLabel.setText("How many top spacings are there?(Top Spacings must be in figures)");
                        valid = false;
                    }
                    topSpacingsLabel.updateUI();
                }


                if (valid) {
                    if (trussType.equals("Howe")) {
                        ///set up Howe things
                        setUpHowe();
                    } else if (trussType.equals("Fink")) {
                        ///set up Fink things 
                        setUpFink();
                    }

                }
                setBounds(0, 0, getPreferredSize().width + 20, getPreferredSize().height + 20);
            } else if (e.getSource() == addWidthsButton) {
                widths = new double[spacings];
                for (int i = 0; i < wFields.length; i++) {
                    widths[i] = Integer.parseInt(wFields[i].getText());
                }
                setWidths(widths);
                if (trussType.equals("Howe")) {
                    displayForces(spacings - 1);
                } else if (trussType.equals("Fink")) {
                    displayForces(spacings);
                }
            } else if (e.getSource() == addForcesButton) {
                if (trussType.equals("Howe")) {
                    forces = new double[spacings - 1];
                } else if (trussType.equals("Fink")) {
                    forces = new double[spacings];
                }
                for (int i = 0; i < fFields.length; i++) {
                    forces[i] = Integer.parseInt(fFields[i].getText());
                }
                setForces(forces);
                if (trussType.equals("Howe")) {
                    setUpHoweExtras(Math.toRadians(pitch));
                } else if (trussType.equals("Fink")) {
                    setUpFinkExtras(Math.toRadians(pitch));
                }
            } else if (e.getSource() == addAsButton) {
                as = new double[spacings];
                for (int i = 0; i < aFields.length; i++) {
                    as[i] = Integer.parseInt(aFields[i].getText());
                }
                setAs(as);
                if (trussType.equals("Fink")) {
                    displayWidths(topSpacings);

                }

            }
        }
    }

    class DropdownActionListener implements ActionListener {

        @Override
        public void actionPerformed(ActionEvent ae) {
            if (ae.getSource() == trussTypeCombo) {
                if (trussTypeCombo.getSelectedItem().toString().equals("Howe")) {
                    spacingsLabel.setText("How many spacings are there?");
                    spacingsLabel.updateUI();
                } else if (trussTypeCombo.getSelectedItem().toString().equals("Fink")) {
                    spacingsLabel.setText("How many bottom spacings are there?");
                    topSpacingsField = new JTextField();
                    topSpacingsLabel = new JLabel("How many top spacings are there?");
                    questionPanel.add(topSpacingsLabel);
                    questionPanel.add(topSpacingsField);
                    spacingsLabel.updateUI();
                }
            }
        }
    }

    public void setUpFink() {

        while (wModel.getRowCount() > 0) {
            wModel.removeRow(wModel.getRowCount() - 1);
        }
        displayAs(spacings);
        pitchModel.addRow(new Object[]{"Pitch(degrees)", pitch});
        double pitchInRadians = Math.toRadians(pitch);
        pitchModel.addRow(new Object[]{"Pitch(radians)", pitchInRadians});
        pitchModel.addRow(new Object[]{"Sin(Pitch)", Math.sin(pitchInRadians)});
        pitchModel.addRow(new Object[]{"Cos(Pitch)", Math.cos(pitchInRadians)});
        pitchModel.addRow(new Object[]{"Tan(pitch)", Math.tan(pitchInRadians)});
        double pitch2 = 90 - pitch;
        pitchModel.addRow(new Object[]{"90-Pitch", pitch2});
        double pitch2InRadians = Math.toRadians(pitch2);
        pitchModel.addRow(new Object[]{"90-Pitch(radians)", pitch2InRadians});
        pitchModel.addRow(new Object[]{"Tan(90-Pitch)", Math.tan(pitch2InRadians)});
    }

    public double getXn(int n) {
        double xn = 0;
        if (n == 1) {

            xn = Math.atan((widths[1] / widths[0]) * Math.tan(Math.toRadians(90 - pitch)));
        } else {
            xn = Math.atan(widths[n] / getSumOfWn(n) * Math.tan(Math.toRadians(90 - pitch)));
        }
        return xn;
    }

    public double getTn(double xn, int n) {
        double tn = 0;
        System.out.println("Sum " + getSumOfWn(n + 1));
        System.out.println("xn " + xn);
//        System.out.println("Sum "+ getSumOfWn(n + 1));
//        System.out.println("Tan tn "+xn / (Math.tan(Math.toRadians(pitch)) * getSumOfWn(n + 1)));
        tn = Math.atan(xn / (Math.tan(Math.toRadians(pitch)) * getSumOfWn(n + 1)));
        return tn;
    }

    public double getSumOfWn(int n) {
        double sum = 0;
        for (int i = 0; i < n; i++) {
            sum += widths[i];
        }
        return sum;
    }

    public void setUpHowe() {

        while (wModel.getRowCount() > 0) {
            wModel.removeRow(wModel.getRowCount() - 1);
        }
        displayWidths(spacings);

        pitchModel.addRow(new Object[]{"Pitch(degrees)", pitch});
        double pitchInRadians = Math.toRadians(pitch);
        pitchModel.addRow(new Object[]{"Pitch(radians)", pitchInRadians});
        pitchModel.addRow(new Object[]{"Sin(Pitch)", Math.sin(pitchInRadians)});
        pitchModel.addRow(new Object[]{"Cos(Pitch)", Math.cos(pitchInRadians)});
        pitchModel.addRow(new Object[]{"Tan(pitch)", Math.tan(pitchInRadians)});
        double pitch2 = 90 - pitch;
        pitchModel.addRow(new Object[]{"90-Pitch", pitch2});
        double pitch2InRadians = Math.toRadians(pitch2);
        pitchModel.addRow(new Object[]{"90-Pitch(radians)", pitch2InRadians});
        pitchModel.addRow(new Object[]{"Tan(90-Pitch)", Math.tan(pitch2InRadians)});
        double pitch3 = 90 + pitch;
        double pitch3InRadians = Math.toRadians(pitch3);
        pitchModel.addRow(new Object[]{"Tan(90+Pitch)", pitch3InRadians});

    }

    public void setUpHoweExtras(double pitchInRadians) {
        double Ftop1[] = new double[spacings];
        Ftop1[0] = -(reaction / Math.sin(pitchInRadians));
        double Fbot[] = new double[spacings];
        Fbot[0] = (reaction / Math.tan(pitchInRadians));
        pitchModel.addRow(new Object[]{"Ftop1", Ftop1[0]});
        pitchModel.addRow(new Object[]{"Fbot1", Fbot[0]});
        pitchModel.addRow(new Object[]{"Fint20", 0});
        pitchModel.addRow(new Object[]{"x0", 0});
        pitchModel.addRow(new Object[]{"Sin x0", Math.sin(0)});

        double xn[] = new double[spacings];
        double Fint2[] = new double[spacings];
        Fint2[0] = 0;
        xn[0] = 0;
        if (spacings > 1) {
            for (int i = 1; i < spacings; i++) {
                xn[i] = getXn(i);

                pitchModel.addRow(new Object[]{"x" + i, xn[i]});
                pitchModel.addRow(new Object[]{"Sin x" + i, Math.sin(xn[i])});
                pitchModel.addRow(new Object[]{"Cos x" + i, Math.cos(xn[i])});
                double yn = Math.toRadians(90 + pitch) - xn[i];
                pitchModel.addRow(new Object[]{"y" + i, yn});
                pitchModel.addRow(new Object[]{"Sin y" + i, Math.sin(yn)});
                double hn = 0;
                double Fint1n = Fint2[i - 1] * Math.cos(xn[i - 1]);
                if (i < 2) {
                    hn = Math.sin(xn[i]) / Math.sin(yn);
                    System.out.println("Choice 1 hn " + i + " " + hn);
                    pitchModel.addRow(new Object[]{"hn", hn});
                } else if (i > 1) {
                    hn = (Fint1n + forces[i - 1]) * (Math.sin(xn[i]) / Math.sin(yn));
                    System.out.println("Choice 2 hn " + i + " " + hn);
                    pitchModel.addRow(new Object[]{"hn", hn});
                }
                if (i == 1) {
                    Ftop1[i] = Ftop1[i - 1] + hn;
                    pitchModel.addRow(new Object[]{"Ftop" + (i + 1), Ftop1[i]});
                } else if (i > 1) {
                    Ftop1[i] = Ftop1[i - 1] + (Fint1n + forces[i - 1]) * (Math.sin(xn[i]) / Math.sin(yn));
                    pitchModel.addRow(new Object[]{"Ftop" + (i + 1), Ftop1[i]});
                }

                if (i == 1) {
                    Fbot[i] = Fbot[i - 1] * Math.cos(xn[i - 1]);
                    pitchModel.addRow(new Object[]{"Fbot" + (i + 1), Fbot[i]});
                } else if (i > 1) {
                    Fbot[i] = Fbot[i - 1] - (Fint2[i - 1] * Math.sin(xn[i - 1]));
                    pitchModel.addRow(new Object[]{"Fbot" + (i + 1), Fbot[i]});
                }

                if (i > 0) {
                    Fint2[i] = (Math.cos(pitchInRadians) / Math.sin(yn)) * (Fint1n + forces[i - 1]);
                }
                pitchModel.addRow(new Object[]{"Fint2" + i, Fint2[i]});
                pitchModel.addRow(new Object[]{"Fint1" + i, Fint1n});
            }

        }
    }

    public void setUpFinkExtras(double pitchInRadians) {
        double xn[] = new double[widths.length];
        for (int i = 0; i < widths.length; i++) {
            xn[i] = getFinkXn(i);
            pitchModel.addRow(new Object[]{"x" + (i + 1), xn[i]});
        }
        double Ftop[] = new double[spacings];
        Ftop[0] = -(reaction / Math.sin(pitchInRadians));
        double Fbot1[] = new double[spacings];
        Fbot1[0] = (reaction / Math.tan(pitchInRadians));
        pitchModel.addRow(new Object[]{"Ftop1", Ftop[0]});
        pitchModel.addRow(new Object[]{"Fbot1", Fbot1[0]});


        double tn[] = new double[widths.length];
        double sinTn[] = new double[widths.length];
        double cosTn[] = new double[widths.length];
        double M[] = new double[widths.length];
        double sinM[] = new double[widths.length];
        for (int i = 0; i < widths.length; i++) {
            tn[i] = getTn(xn[i], i);
            pitchModel.addRow(new Object[]{"t" + (i + 1), tn[i]});
            sinTn[i] = Math.sin(tn[i]);
            pitchModel.addRow(new Object[]{"Sin t" + (i + 1), sinTn[i]});
            cosTn[i] = Math.cos(tn[i]);
            pitchModel.addRow(new Object[]{"Cos t" + (i + 1), cosTn[i]});
            M[i] = Math.toRadians(90 - pitch) + tn[i];
            pitchModel.addRow(new Object[]{"M" + (i + 1), M[i]});
            sinM[i] = Math.sin(M[i]);
            pitchModel.addRow(new Object[]{"Sin M" + (i + 1), sinM[i]});
        }
        double verticalResultant[] = new double[widths.length];
        verticalResultant[0] = reaction - forces[0];
        pitchModel.addRow(new Object[]{"Vertical resultant 0", verticalResultant[0]});
        for (int i = 1; i < verticalResultant.length; i++) {
            verticalResultant[i] = verticalResultant[i - 1] - forces[i];
            
            pitchModel.addRow(new Object[]{"Vertical resultant" + i, verticalResultant[i]});
        }
        double Fint1[] = new double[widths.length];
        double Fint2[] = new double[widths.length];

        double tanN[] = new double[widths.length];
        double N[] = new double[widths.length];
        double sinN[] = new double[widths.length];
        double cosN[] = new double[widths.length];
        for (int i = 0; i < (tanN.length - 1); i++) {
            tanN[i] = (Math.tan(pitchInRadians) * getSumOfWn(i + 2)) / (widths[i + 1] - xn[i]);
            pitchModel.addRow(new Object[]{"tan N" + (i + 1), tanN[i]});
            N[i] = Math.atan(tanN[i]);
            pitchModel.addRow(new Object[]{"N" + (i + 1), N[i]});
            sinN[i] = Math.sin(N[i]);
            pitchModel.addRow(new Object[]{"Sin N" + (i + 1), sinN[i]});
            cosN[i] = Math.cos(N[i]);
            pitchModel.addRow(new Object[]{"Cos N" + (i + 1), cosN[i]});
        }
             

        double b = Math.sin(90 - N[0] + tn[0]);
        for (int i = 0; i < Fint1.length; i++) {
            if (i >= 1) {
                Fbot1[i] = Fbot1[i - 1] - Fint1[i - 1] * (Math.sin(Math.toRadians(90) - N[i - 1] + tn[i - 1]) / sinN[i - 1]);
                pitchModel.addRow(new Object[]{"Fbot" + (i + 1), Fbot1[i]});
                }
            Fint1[i] = (Math.sin(pitchInRadians) / sinM[i]) * (Fbot1[i] - (verticalResultant[i] / Math.tan(pitchInRadians)));            
            Fint2[i] = Fint1[i] * (cosTn[i] / sinN[i]);
            pitchModel.addRow(new Object[]{"Fint1" + (i + 1), Fint1[i]});
            pitchModel.addRow(new Object[]{"Fint2" + (i + 1), Fint2[i]});
            if (i >= 1) {
                double z = Math.cos(pitchInRadians) * (Fint1[i] * (Math.sin(Math.toRadians(90) - N[i] + tn[i]) / Math.sin(N[i])));
                System.out.println("z "+z);
                double yn =0.5 * Math.cos(pitchInRadians * (i +2)) * (Math.sin(pitchInRadians - tn[i]) / Math.sin(Math.toRadians(90) - pitchInRadians + tn[i]));
                System.out.println("yn "+yn);
                Ftop[i] = Ftop[i - 1] + (i) * z + ((i+1) * Math.sin(pitchInRadians)) - yn;
                pitchModel.addRow(new Object[]{"Ftop" + (i + 1), Ftop[i]});
            }
        }


    }

    public double getFinkXn(int n) {
        double sumA = 0;
        double sumW = 0;
        for (int i = 0; i <= n; i++) {
            sumA += as[i];
            sumW += widths[i];
        }
        return sumA - sumW;

    }

    public void displayWidths(int spacings) {

        widthsPanel.removeAll();
        widthsPanel.updateUI();
        JLabel wLabels[] = new JLabel[spacings];
        wFields = new JTextField[spacings];
        widthsPanel.setLayout(new GridLayout(spacings + 1, 2));
        for (int i = 0; i < spacings; i++) {
            wLabels[i] = new JLabel("W" + (i + 1));
            wFields[i] = new JTextField();
            widthsPanel.add(wLabels[i]);
            widthsPanel.add(wFields[i]);
        }
        addWidthsButton = new JButton("Add Widths");
        widthsPanel.add(addWidthsButton);
        widthsPanel.setBounds(100, 100, getPreferredSize().width, getPreferredSize().height);
        ButtonListener listen = new ButtonListener();
        addWidthsButton.addActionListener(listen);
        widthsPanel.updateUI();
        setBounds(0, 0, getPreferredSize().width + 20, getPreferredSize().height + 20);

    }

    public void displayAs(int spacings) {

        widthsPanel.removeAll();
        widthsPanel.updateUI();
        JLabel aLabels[] = new JLabel[spacings];
        aFields = new JTextField[spacings];
        widthsPanel.setLayout(new GridLayout(spacings + 1, 2));
        for (int i = 0; i < spacings; i++) {
            aLabels[i] = new JLabel("A" + (i + 1));
            aFields[i] = new JTextField();
            widthsPanel.add(aLabels[i]);
            widthsPanel.add(aFields[i]);
        }
        addAsButton = new JButton("Add As");
        widthsPanel.add(addAsButton);
        widthsPanel.setBounds(100, 100, getPreferredSize().width, getPreferredSize().height);
        ButtonListener listen = new ButtonListener();
        addAsButton.addActionListener(listen);
        widthsPanel.updateUI();
        setBounds(0, 0, getPreferredSize().width + 20, getPreferredSize().height + 20);

    }

    //set up forces
    public void displayForces(int spacingCount) {

        widthsPanel.removeAll();
        widthsPanel.updateUI();
        JLabel fLabels[] = new JLabel[spacingCount];
        fFields = new JTextField[spacingCount];
        widthsPanel.setLayout(new GridLayout(spacingCount + 1, 2));
        for (int i = 0; i < spacingCount; i++) {
            fLabels[i] = new JLabel("F" + (i + 1));
            fFields[i] = new JTextField();
            widthsPanel.add(fLabels[i]);
            widthsPanel.add(fFields[i]);
        }
        addForcesButton = new JButton("Add forces");
        widthsPanel.add(addForcesButton);
        widthsPanel.setBounds(100, 100, getPreferredSize().width, getPreferredSize().height);
        ButtonListener listen = new ButtonListener();
        addForcesButton.addActionListener(listen);
        widthsPanel.updateUI();
        setBounds(0, 0, getPreferredSize().width + 20, getPreferredSize().height + 20);

    }

    //set up widths
    public void setWidths(double widths[]) {
        for (int i = 0; i < widths.length; i++) {
            wModel.addRow(new Object[]{"W" + (i + 1), widths[i]});
        }

        setBounds(0, 0, getPreferredSize().width + 20, getPreferredSize().height + 20);
    }

    public void setForces(double forces[]) {
        for (int i = 0; i < forces.length; i++) {
            wModel.addRow(new Object[]{"F" + (i + 1), forces[i]});
        }
        setBounds(0, 0, getPreferredSize().width + 20, getPreferredSize().height + 20);
    }

    //set up as
    public void setAs(double as[]) {

        for (int i = 0; i < as.length; i++) {
            wModel.addRow(new Object[]{"A" + (i + 1), as[i]});
        }
        setBounds(0, 0, getPreferredSize().width + 20, getPreferredSize().height + 20);
    }

    public static void main(String args[]) {
        MainFrame mainFrame = new MainFrame();
        mainFrame.setVisible(true);
        mainFrame.pack();
    }
}
